package com.common.library.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;


/**
 * 
 * function: 输入法控制
 * 
 * @ author: aXiBa 2011-11-10
 */
public class InputMethodeUtil {
	
	/**
	 * 
	 * function: 如输入法关闭则打开
	 *
	 * 
	 * @ author: aXiBa 2011-11-10 下午03:15:44
	 */
	public static void openInputMethod(Context context, View view) {

		InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
		if(!imm.isActive()) {
			imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
		}
    }
	
	
	/**
	 * 
	 * function: 如输入法打开则关闭
	 *
	 * @param act
	 * 
	 * @ author: aXiBa 2011-11-10 下午03:27:59
	 */
	public static void closeInputMethod(Activity act) {
		if (act.getCurrentFocus() != null) {
			InputMethodManager imm = (InputMethodManager)act.getSystemService(Context.INPUT_METHOD_SERVICE);
			if(imm.isActive()) {
				imm.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}
	}
	
	
	/**
	 * 
	 * function: 切换输入法的状态
	 *
	 * 
	 * @ author: aXiBa 2011-11-10 下午03:16:25
	 */
	public static void toggleInputMethod(Context context) {
		
		InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	}
}